from dataclasses import dataclass
from typing import Set, List, cast, Any

import pandas as pd

@dataclass
class Student:
    number: str
    name: str
    failed_problems: Set[int]

def row_to_student(problems: List[int]):
    def inner(row: pd.Series,):
        number = str(row["学号"])
        name = str(row["姓名"])
        failed_problems = set()
        for p in problems:
            if row[p] == '×':
                failed_problems.add(p)
        return Student(number, name, failed_problems)
    return inner


def read_students(file_path: str) -> List[Student]:
    sheet = pd.read_excel(file_path, sheet_name=0)
    all_problems = [int(cast(Any, sheet.columns[i])) for i in range(2, len(sheet.columns))]
    students = [ row_to_student(all_problems)(row) for _,row in sheet.iterrows() ]
    return students

